home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / dopus412-gpl / program / main13.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  10KB  |  348 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "DOpus.h"
  32.  
  33. void seedate(ds,date,pad)
  34. struct DateStamp *ds;
  35. char *date;
  36. int pad;
  37. {
  38.     char timebuf[16],datebuf[16],buf[40];
  39.     struct DOpusDateTime dt;
  40.  
  41.     copy_datestamp(ds,&dt.dat_Stamp);
  42.     initdatetime(&dt,datebuf,timebuf,1);
  43.  
  44.     strncpy(buf,datebuf,9);
  45.     buf[9]=0;
  46.     strcat(buf," ");
  47.     strcat(buf,timebuf);
  48.     buf[19]=0;
  49.  
  50.     if (pad) {
  51.         if (config->dateformat&DATE_12HOUR) lsprintf(date,"%19s",buf);
  52.         else lsprintf(date,"%18s",buf);
  53.     }
  54.     else strcpy(date,buf);
  55. }
  56.  
  57. setdate(name,date)
  58. char *name;
  59. struct DateStamp *date;
  60. {
  61.     struct MsgPort *handler;
  62.     ULONG arg[4];
  63.     BPTR lock,parentlock;
  64.     APTR wsave;
  65.     int rc=0;
  66.     char __aligned bstrname[40];
  67.  
  68.     wsave=main_proc->pr_WindowPtr;
  69.     main_proc->pr_WindowPtr=(APTR)-1;
  70.  
  71.     if (handler=(struct MsgPort *)DeviceProc(name)) {
  72.         if (lock=Lock(name,ACCESS_READ)) {
  73.             parentlock=ParentDir(lock);
  74.             UnLock(lock);
  75.  
  76.             strcpy(&bstrname[1],BaseName(name));
  77.             bstrname[0]=strlen(&bstrname[1]);
  78.  
  79.             arg[0]=0;
  80.             arg[1]=(ULONG)parentlock;
  81.             arg[2]=(ULONG)bstrname>>2;
  82.             arg[3]=(ULONG)date;
  83.             rc=SendPacket(handler,ACTION_SET_DATE,arg,4);
  84.             UnLock(parentlock);
  85.         }
  86.     }
  87.  
  88.     main_proc->pr_WindowPtr=wsave;
  89.     return(rc?1:IoErr());
  90. }
  91.  
  92. void seename(win)
  93. int win;
  94. {
  95.     int tot,bl,a;
  96.     static char buf[256];
  97.  
  98.     if (win<0 || status_iconified) return;
  99.     if (!dopus_curwin[win]->firstentry ||
  100.         (dopus_curwin[win]->firstentry->type!=ENTRY_DEVICE &&
  101.         dopus_curwin[win]->firstentry->type!=ENTRY_CUSTOM)) {
  102.         if (str_pathbuffer[win][0]==0) {
  103.             if (win==data_active_window)
  104.                 SetAPen(main_rp,screen_pens[config->disknameselbg].pen);
  105.             else SetAPen(main_rp,screen_pens[config->disknamebg].pen);
  106.             rectfill(main_rp,
  107.                 scrdata_diskname_xpos[win]+2,scrdata_diskname_ypos,
  108.                 scrdata_diskname_width[win],scrdata_diskname_height-2);
  109.             SetAPen(main_rp,screen_pens[1].pen);
  110.             return;
  111.         }
  112.         else {
  113.             strcpy(buf,str_pathbuffer[win]);
  114.             dopus_curwin[win]->diskname[0]=0;
  115.             main_proc->pr_WindowPtr=(APTR)-1;
  116.             if (!(a=getroot(buf,NULL))) {
  117.                 strcpy(dopus_curwin[win]->diskname,globstring[STR_DIR_NOT_AVAILABLE_TITLE]);
  118.                 dopus_curwin[win]->disktot=dopus_curwin[win]->diskfree=dopus_curwin[win]->diskblock=-1;
  119.                 displayname(win,1);
  120.                 if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
  121.                 return;
  122.             }
  123.             strcpy(dopus_curwin[win]->diskname,buf);
  124. /* */
  125.             strcpy(dopus_curwin[win]->volumename,buf);
  126. /* */
  127.             dopus_curwin[win]->diskfree=bytes(str_pathbuffer[win],&tot,&bl);
  128.             dopus_curwin[win]->disktot=tot;
  129.             dopus_curwin[win]->diskblock=bl;
  130.             if (a==ID_WRITE_PROTECTED) dopus_curwin[win]->flags|=DWF_READONLY;
  131.             else dopus_curwin[win]->flags&=~DWF_READONLY;
  132.             if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
  133.         }
  134.     }
  135.     displayname(win,0);
  136. }
  137.  
  138. void displayname(win,clear)
  139. int win,clear;
  140. {
  141.     int free,b,tot,x,nn=0,len,len2,len3,x1,cx1,cx2;
  142.     static char buf[30],buf2[80],buf3[20];
  143.     double pct;
  144.  
  145.     if (status_iconified || win<0) return;
  146.     if (str_pathbuffer[win][0]==0) {
  147.         if (dopus_curwin[win]->disktot!=-1 &&
  148.             (!dopus_curwin[win]->firstentry || dopus_curwin[win]->firstentry->type!=ENTRY_DEVICE)) nn=2;
  149.         else nn=1;
  150.     }
  151.     if (nn!=2) {
  152.         free=dopus_curwin[win]->diskfree; tot=dopus_curwin[win]->disktot;
  153.         SetDrMd(main_rp,JAM2);
  154.         StrCombine(buf2,dopus_curwin[win]->diskname,str_space_string,32);
  155.         SetFont(main_rp,scr_font[FONT_NAMES]);
  156.  
  157.         len=30;
  158.         x1=dotextlength(main_rp,buf2,&len,scrdata_diskname_width[win]-4);
  159.  
  160.         if (!nn && tot>-1) {
  161.             if (config->showfree&SHOWFREE_BYTES || config->showfree==0) {
  162.                 if (dopus_curwin[win]->flags&DWF_READONLY)
  163.                     lsprintf(buf," (%ld)",free);
  164.                 else lsprintf(buf," %ld",free);
  165.             }
  166.             else if (config->showfree&SHOWFREE_KILO) {
  167.                 getsizestring(buf,free);
  168.                 if (dopus_curwin[win]->flags&DWF_READONLY) {
  169.                     char buf1[30];
  170.  
  171.                     strcpy(buf1,"(");
  172.                     strcat(buf1,buf);
  173.                     strcat(buf1,")");
  174.                     strcpy(buf,buf1);
  175.                 }
  176.             }
  177.             else if (config->showfree&SHOWFREE_BLOCKS) {
  178.                 if (dopus_curwin[win]->flags&DWF_READONLY)
  179.                     lsprintf(buf," (%ld)",dopus_curwin[win]->diskblock);
  180.                 else lsprintf(buf," %ld",dopus_curwin[win]->diskblock);
  181.             }
  182.             else if (config->showfree&SHOWFREE_PERCENT) {
  183.                 if (tot==0) b=100;
  184.                 else {
  185.                     pct=free; pct*=100;
  186.                     b=(int)(pct/(double)tot);
  187.                 }
  188.                 if (b>100) b=100;
  189.                 if (dopus_curwin[win]->flags&DWF_READONLY)
  190.                     lsprintf(buf," (%ld%%)",b);
  191.                 else lsprintf(buf," %ld%%",b);
  192.             }
  193.             StrCombine(buf3,buf,str_space_string,14);
  194.             len2=12; len3=strlen(buf);
  195.             FOREVER {
  196.                 x=dotextlength(main_rp,buf3,&len2,scrdata_diskname_width[win]-x1-4);
  197.                 if (len2>=len3 || (--len)==0) break;
  198.                 len2=12; x1=dotextlength(main_rp,buf2,&len,scrdata_diskname_width[win]-4);
  199.             }
  200.             strncpy(buf3,str_space_string,13);
  201.             strcpy(&buf3[len2-len3],buf);
  202.         }
  203.         else x=0;
  204.     }
  205.  
  206.     if (clear) {
  207.         if (win==data_active_window)
  208.             SetAPen(main_rp,screen_pens[config->disknameselbg].pen);
  209.         else SetAPen(main_rp,screen_pens[config->disknamebg].pen);
  210.         rectfill(main_rp,
  211.             scrdata_diskname_xpos[win]+2,
  212.             scrdata_diskname_ypos,
  213.             scrdata_diskname_width[win],
  214.             scrdata_diskname_height-2);
  215.     }
  216.  
  217.     if (nn!=2) {
  218.         if (win==data_active_window) {
  219.             SetAPen(main_rp,screen_pens[config->disknameselfg].pen);
  220.             SetBPen(main_rp,screen_pens[config->disknameselbg].pen);
  221.         }
  222.         else {
  223.             SetAPen(main_rp,screen_pens[config->disknamefg].pen);
  224.             SetBPen(main_rp,screen_pens[config->disknamebg].pen);
  225.         }
  226.  
  227.         Move(main_rp,
  228.             scrdata_diskname_xpos[win]+4,
  229.             scrdata_diskname_ypos+scr_font[FONT_NAMES]->tf_Baseline);
  230.         Text(main_rp,buf2,len);
  231.  
  232.         cx1=main_rp->cp_x;
  233.         if (x) {
  234.             x1=(scrdata_diskname_xpos[win]+scrdata_diskname_width[win])-x;
  235.             if (x1<scrdata_diskname_xpos[win]+2) x1=scrdata_diskname_xpos[win]+2;
  236.             cx2=x1-1;
  237.             Move(main_rp,x1,scrdata_diskname_ypos+scr_font[FONT_NAMES]->tf_Baseline);
  238.             Text(main_rp,buf3,len2);
  239.         }
  240.         else cx2=scrdata_diskname_xpos[win]+scrdata_diskname_width[win]+1;
  241.         if (!clear && cx1<=cx2) {
  242.             SetAPen(main_rp,main_rp->BgPen);
  243.             RectFill(main_rp,cx1,scrdata_diskname_ypos,cx2,scrdata_diskname_height+scrdata_diskname_ypos-3);
  244.         }
  245.         SetFont(main_rp,scr_font[FONT_GENERAL]);
  246.     }
  247. }
  248.  
  249. void relabel_disk(rexx,path)
  250. int rexx;
  251. char *path;
  252. {
  253.     struct MsgPort *port;
  254.     char oldname[33],name[33],*bstr;
  255.     ULONG arg;
  256.     char buf[256];
  257.     int a;
  258.  
  259.     if (rexx) strcpy(buf,rexx_args[0]);
  260.     else strcpy(buf,path);
  261.  
  262.     if (!(getroot(buf,NULL))) {
  263.         doerror(IoErr());
  264.         return;
  265.     }
  266.     strcat(buf,":");
  267.     if (!(port=(struct MsgPort *) DeviceProc(buf))) return;
  268.     getroot(buf,NULL);
  269.  
  270.     strcpy(name,buf); strcpy(oldname,name);
  271.     if (!rexx) {
  272.         if (!(whatsit(globstring[STR_ENTER_NEW_DISK_NAME],30,name,NULL))) return;
  273.     }
  274.     else strcpy(name,rexx_args[1]);
  275.     a=strlen(name);
  276.     bstr=(char *) AllocMem(a+2,MEMF_CLEAR);
  277.     bstr[0]=(char)a;
  278.     strcpy(bstr+1,name);
  279.     arg=(ULONG)bstr>>2;
  280.     if (!(SendPacket(port,ACTION_RENAME_DISK,&arg,1))) doerror(IoErr());
  281.     else if (!status_iconified) {
  282.         if ((LStrnCmpI(str_pathbuffer[data_active_window],oldname,strlen(oldname)))==0 &&
  283.             str_pathbuffer[data_active_window][strlen(oldname)]==':') {
  284.             strcpy(buf,name);
  285.             StrConcat(buf,&str_pathbuffer[data_active_window][strlen(oldname)],256);
  286.             strcpy(str_pathbuffer[data_active_window],buf);
  287.             checkdir(str_pathbuffer[data_active_window],&path_strgadget[data_active_window]);
  288.             strcpy(dopus_curwin[data_active_window]->directory,str_pathbuffer[data_active_window]);
  289.         }
  290.         seename(data_active_window);
  291.     }
  292.     FreeMem(bstr,a+2);
  293. }
  294.  
  295. getroot(name,ds)
  296. char *name;
  297. struct DateStamp *ds;
  298. {
  299.     BPTR lock1;
  300.     struct FileLock *lock2;
  301.     struct InfoData __aligned info;
  302.     char *p;
  303.     struct DeviceList *dl;
  304.     int a;
  305.  
  306.     if (!(lock1=Lock(name,ACCESS_READ))) return(0);
  307.     lock2=(struct FileLock *) BADDR(lock1);
  308.     for (a=0;a<32;a++) name[a]=0;
  309.     dl=(struct DeviceList *)BADDR(lock2->fl_Volume);
  310.     p=(char *) BADDR(dl->dl_Name);
  311.     if (p) LStrnCpy(name,p+1,*p);
  312.     if (ds) CopyMem((char *)&dl->dl_VolumeDate,(char *)ds,sizeof(struct DateStamp));
  313.     Info(lock1,&info);
  314.     UnLock(lock1);
  315.     return(info.id_DiskState);
  316. }
  317.  
  318. BPTR getrootlock(lock1)
  319. BPTR lock1;
  320. {
  321.     BPTR lock2;
  322.  
  323.     while ((lock2=ParentDir(lock1))) {
  324.         UnLock(lock1);
  325.         lock1=lock2;
  326.     }
  327.     return(lock1);
  328. }
  329.  
  330. void strtostamp(date,time,ds)
  331. char *date,*time;
  332. struct DateStamp *ds;
  333. {
  334.     struct DOpusDateTime datetime;
  335.  
  336.     datetime.dat_Format=dateformat(config->dateformat);
  337.     datetime.dat_Flags=DDTF_SUBST|DDTF_CUSTOM;
  338.     datetime.dat_StrDate=date;
  339.     datetime.dat_StrTime=time;
  340.     datetime.custom_months=date_months;
  341.     datetime.custom_shortmonths=date_shortmonths;
  342.     datetime.custom_weekdays=date_weekdays;
  343.     datetime.custom_shortweekdays=date_shortweekdays;
  344.     datetime.custom_special_days=date_special;
  345.     StrToStamp(&datetime);
  346.     copy_datestamp(&datetime.dat_Stamp,ds);
  347. }
  348.